package dbz.domain.actions;

import java.util.ArrayList;
import java.util.List;

import dbz.domain.Fighter;
import dbz.domain.Match;
import dbz.domain.attack.Attack;

public class ActionAnalyzer {

	private Match match;
	
	public ActionAnalyzer(Match match) {
		this.match = match;
	}
	
	public List<Action> analizePosibleActiveActions() {
		List<Action> posibleActions = new ArrayList<Action>();
		if(activePlayerIsAbleToPowerUp()) {
			 posibleActions.add(new PowerUpAction(match.getCurrentTurn().getAttackingFighter(), match.getCurrentTurn().getActivePlayer().getHand().getAnyKiCard()));
		}
		analizeAttackingActions(posibleActions);
		posibleActions.add(new EndTurnAction(match));
		return posibleActions;
	}

	private void analizeAttackingActions(List<Action> posibleActions) {
		if(match.getTurnNumber() < 3)
			return;
		Fighter attackingFighter = match.getCurrentTurn().getAttackingFighter();
		for(Attack attack : attackingFighter.getAttacks().values()) {
			if(attack.areConditionsSatisfied()) {
				posibleActions.add(new AttackAction(attackingFighter, match.getCurrentTurn().getDefensiveFighter(), attack.getName()));
			}
		}
	}

	

	private boolean activePlayerIsAbleToPowerUp() {
		return match.getCurrentTurn().isAbleToPowerUp() && 
		match.getCurrentTurn().getActivePlayer().getHand().hasKiCard();
	}
}
